﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.Electric;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.MEP.Electric.Common;
using YArchitech.Revit.Electric.Common;
//using YArchitech.Revit.MEP.Calculator;

namespace HYRElectric.SystemDiagram
{
	public partial class SystemCreateForm : System.Windows.Forms.Form
	{
		public BusInfo BusData
		{
			get
			{
				return this.m_busInfo;
			}
		}

		public LoopCommonInfo LoopCommonData
		{
			get
			{
				return this.m_loopCommonInfo;
			}
		}

		public List<LoopInfo> LoopData
		{
			get
			{
				return this.m_loopInfo;
			}
		}

		public List<string> BusCalculateData
		{
			get
			{
				return this.m_busCalculateInfo;
			}
		}

		public List<CellInfo> CellInfos
		{
			get
			{
				return this.m_cells;
			}
		}

		public SystemCreateForm(Document doc)
		{
			this.InitializeComponent();
			this.InitAllCells(doc);
			if (!this.ReadFileData())
			{
				this.InitSystemDiagramData();
			}
			this.InitDlgData();
			this.m_BmpListForm = new BmpListForm(this);
			this.m_dictionary = new Dictionary<string, List<string>>();
			this.m_xmlTagData = new YArchitech.MEP.Electric.Common.XmlHelper();
			string xmlPath = Path.Combine(Product.DataLocation, "ElectricalData", "SystemSwitchTag.xml");
			this.m_xmlTagData.LoadXml(xmlPath, "SwitchTags");
			this.m_dictionary = new Dictionary<string, List<string>>();
			this.GetAllTags();
		}

		private void InitSystemDiagramData()
		{
			this.xmlHelper.LoadXml(this.path, "SystemDiagram");
			this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "BusWire"));
			string busModel = "BV";
			string busWiring = "SC";
			List<string> list = new List<string>();
			List<string> list2 = new List<string>();
			list.Add("空");
			list2.Add("");
			list.Add("断路器");
			list2.Add("");
			this.m_busInfo = new BusInfo(busModel, busWiring, list, list2);
			string loopModel = "BV";
			string loopWiring = "SC";
			this.m_loopCommonInfo = new LoopCommonInfo(loopModel, loopWiring);
			this.m_loopInfo = new List<LoopInfo>();
			for (int i = 1; i < 9; i++)
			{
				string loopName = string.Format("WL{0}", i);
				string phaseSequence = "单相";
				double load = 1.0;
				double coefficient = 0.8;
				double power = 0.8;
				string use = "照明";
				double current = 4.55;
				List<string> list3 = new List<string>();
				List<string> list4 = new List<string>();
				list3.Add("断路器");
				list4.Add("");
				list3.Add("空");
				list4.Add("");
				list3.Add("空");
				list4.Add("");
				LoopInfo item = new LoopInfo(loopName, phaseSequence, load, coefficient, power, use, current, list3, list4, 0.0, 0.0);
				this.m_loopInfo.Add(item);
			}
		}

		private void InitAllCells(Document doc)
		{
			try
			{
				List<DbFamilyObject> list = new FamilyLibDataAssist(doc, "SystemGraphSwitch").LoadFamilyDatas(null);
				this.m_cells = new List<CellInfo>();
				foreach (DbFamilyObject dbFamilyObject in list)
				{
					string text = dbFamilyObject.Name;
					Image image = Image.FromFile(dbFamilyObject.Image2D);
					string family = dbFamilyObject.Family;
					CellInfo item = new CellInfo(text, image, family);
					this.m_cells.Add(item);
				}
			}
			catch
			{
				TaskDialog.Show("盈建科", "数据库中SystemGraphSwitch表读取错误！");
			}
		}

		private void InitDlgData()
		{
			if (this.cmbInstallType.Text == "")
			{
				this.cmbInstallType.Text = this.cmbInstallType.Items[0].ToString();
			}
			this.cmbBusModel.Items.Clear();
			this.cmbBusModel.Items.Add("BV");
			this.cmbBusModel.Items.Add("ZRBV");
			this.cmbBusModel.Text = this.m_busInfo.busModel;
			this.cmbBusWiring.Items.Clear();
			this.cmbBusWiring.Items.Add("SC");
			this.cmbBusWiring.Items.Add("PC");
			this.cmbBusWiring.Text = this.m_busInfo.busWiring;
			this.picElement1.Image = DistributionBoxCommon.GetCellImageByName(this.m_busInfo.busCells[0], this.m_cells);
			this.picElement1.Text = this.m_busInfo.busCells[0];
			this.picElement2.Image = DistributionBoxCommon.GetCellImageByName(this.m_busInfo.busCells[1], this.m_cells);
			this.picElement2.Text = this.m_busInfo.busCells[1];
			this.txtTag1.Text = this.m_busInfo.busTags[0];
			this.txtTag2.Text = this.m_busInfo.busTags[1];
			if (this.picElement1.Text == "空")
			{
				this.txtTag1.Enabled = false;
				this.btnTag1.Enabled = false;
			}
			if (this.picElement2.Text == "空")
			{
				this.txtTag2.Enabled = false;
				this.btnTag2.Enabled = false;
			}
			this.cmbLoopModel.Items.Clear();
			this.cmbLoopModel.Items.Add("BV");
			this.cmbLoopModel.Items.Add("ZRBV");
			this.cmbLoopModel.Text = this.m_loopCommonInfo.loopModel;
			this.cmbLoopWiring.Items.Clear();
			this.cmbLoopWiring.Items.Add("SC");
			this.cmbLoopWiring.Items.Add("PC");
			this.cmbLoopWiring.Text = this.m_loopCommonInfo.loopWiring;
			this.m_cmbSelectValue.DropDownStyle = ComboBoxStyle.DropDownList;
			this.m_cmbSelectValue.SelectedIndexChanged += this.cmbSelectValue_SelectedIndexChanged;
			this.m_cmbSelectValue.Click += this.cmbSelectValue_Click;
			this.m_cmbSelectValue.Leave += this.cmbSelectValue_Leave;
			this.m_cmbSelectValue.Visible = false;
			this.dataGridView1.Controls.Add(this.m_cmbSelectValue);
			this.dataGridView1.Rows.Clear();
			if (this.m_loopInfo.Count > 0)
			{
				foreach (LoopInfo loopInfo in this.m_loopInfo)
				{
					this.AddRowInGrid(loopInfo);
				}
				this.m_rowIndex = 0;
				this.dataGridView1.Rows[0].Selected = true;
				this.groupBox2.Text = this.m_loopInfo[0].loopName;
				this.picElement3.Image = DistributionBoxCommon.GetCellImageByName(this.m_loopInfo[0].cells[0], this.m_cells);
				this.picElement3.Text = this.m_loopInfo[0].cells[0];
				this.picElement4.Image = DistributionBoxCommon.GetCellImageByName(this.m_loopInfo[0].cells[1], this.m_cells);
				this.picElement4.Text = this.m_loopInfo[0].cells[1];
				this.picElement5.Image = DistributionBoxCommon.GetCellImageByName(this.m_loopInfo[0].cells[2], this.m_cells);
				this.picElement5.Text = this.m_loopInfo[0].cells[2];
				this.txtTag3.Text = this.m_loopInfo[0].tags[0];
				this.txtTag4.Text = this.m_loopInfo[0].tags[1];
				this.txtTag5.Text = this.m_loopInfo[0].tags[2];
			}
			if (this.picElement3.Text == "空")
			{
				this.txtTag3.Enabled = false;
				this.btnTag3.Enabled = false;
			}
			if (this.picElement4.Text == "空")
			{
				this.txtTag4.Enabled = false;
				this.btnTag4.Enabled = false;
			}
			if (this.picElement5.Text == "空")
			{
				this.btnTag5.Enabled = false;
				this.txtTag5.Enabled = false;
			}
			this.btnAddLoop.Image = YArchitech.Electric.Resources.GetImage("Add20");
			this.btnEditLoop.Image = YArchitech.Electric.Resources.GetImage("ReName20");
			this.btnDeleteLoop.Image = YArchitech.Electric.Resources.GetImage("Delete20");
			this.btnBalancePhase.Image = YArchitech.Electric.Resources.GetImage("Balance20");
			ToolTip toolTip = new ToolTip();
			toolTip.InitialDelay = 500;
			toolTip.AutoPopDelay = 3000;
			toolTip.ReshowDelay = 50;
			toolTip.ShowAlways = true;
			toolTip.SetToolTip(this.btnAddLoop, "添加");
			toolTip.SetToolTip(this.btnEditLoop, "编辑");
			toolTip.SetToolTip(this.btnDeleteLoop, "删除");
			toolTip.SetToolTip(this.btnBalancePhase, "平衡相序");
			toolTip.SetToolTip(this.btnTag1, "管理开关标注");
			toolTip.SetToolTip(this.btnTag2, "管理开关标注");
			toolTip.SetToolTip(this.btnTag3, "管理开关标注");
			toolTip.SetToolTip(this.btnTag4, "管理开关标注");
			toolTip.SetToolTip(this.btnTag5, "管理开关标注");
		}

		private void cmbSelectValue_Click(object sender, EventArgs e)
		{
			if (1 != this.dataGridView1.SelectedRows.Count)
			{
				foreach (object obj in this.dataGridView1.SelectedRows)
				{
					DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
					this.dataGridView1.Rows[dataGridViewRow.Index].Selected = false;
				}
				this.dataGridView1.Rows[this.m_rowIndex].Selected = true;
				this.dataGridView1.CurrentCell = this.dataGridView1.Rows[this.m_rowIndex].Cells[this.m_columnIndex];
			}
		}

		private void cmbSelectValue_Leave(object sender, EventArgs e)
		{
            this.dataGridView1.CurrentCell.Value = ((System.Windows.Forms.ComboBox)sender).Text;
            ((System.Windows.Forms.ComboBox)sender).Visible = false;
			int rowIndex = this.dataGridView1.CurrentCell.RowIndex;
            if (((System.Windows.Forms.ComboBox)sender).Text == "备用")
			{
				this.dataGridView1.Rows[rowIndex].Cells[2].Value = "0";
			}
			this.SetElectricCurrent(rowIndex);
		}

		private void cmbSelectValue_SelectedIndexChanged(object sender, EventArgs e)
		{
		}

		private void picElement1_Click(object sender, EventArgs e)
		{
			this.m_indexPicBox = 0;
			PictureBox pictureBox = sender as PictureBox;
            System.Drawing.Point p = new System.Drawing.Point(pictureBox.Right, pictureBox.Bottom);
			p = this.groupBox1.PointToScreen(p);
            this.m_BmpListForm.Location = new System.Drawing.Point(p.X, p.Y);
			int indexByName = DistributionBoxCommon.GetIndexByName(pictureBox.Text, this.m_cells);
			this.m_BmpListForm.SetSelectIndex(indexByName);
			this.m_BmpListForm.Show();
		}

		private void picElement2_Click(object sender, EventArgs e)
		{
			this.m_indexPicBox = 1;
			PictureBox pictureBox = sender as PictureBox;
            System.Drawing.Point p = new System.Drawing.Point(pictureBox.Right, pictureBox.Bottom);
			p = this.groupBox1.PointToScreen(p);
            this.m_BmpListForm.Location = new System.Drawing.Point(p.X, p.Y);
			int indexByName = DistributionBoxCommon.GetIndexByName(pictureBox.Text, this.m_cells);
			this.m_BmpListForm.SetSelectIndex(indexByName);
			this.m_BmpListForm.Show();
		}

		private void picElement3_Click(object sender, EventArgs e)
		{
			this.m_indexPicBox = 2;
			PictureBox pictureBox = sender as PictureBox;
            System.Drawing.Point p = new System.Drawing.Point(pictureBox.Right, pictureBox.Bottom);
			p = this.groupBox2.PointToScreen(p);
            this.m_BmpListForm.Location = new System.Drawing.Point(p.X, p.Y);
			int indexByName = DistributionBoxCommon.GetIndexByName(pictureBox.Text, this.m_cells);
			this.m_BmpListForm.SetSelectIndex(indexByName);
			this.m_BmpListForm.Show();
			if (1 != this.dataGridView1.SelectedRows.Count)
			{
				foreach (object obj in this.dataGridView1.SelectedRows)
				{
					DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
					this.dataGridView1.Rows[dataGridViewRow.Index].Selected = false;
				}
				this.dataGridView1.Rows[this.m_rowIndex].Selected = true;
			}
		}

		private void picElement4_Click(object sender, EventArgs e)
		{
			this.m_indexPicBox = 3;
			PictureBox pictureBox = sender as PictureBox;
            System.Drawing.Point p = new System.Drawing.Point(pictureBox.Right, pictureBox.Bottom);
			p = this.groupBox2.PointToScreen(p);
            this.m_BmpListForm.Location = new System.Drawing.Point(p.X, p.Y);
			int indexByName = DistributionBoxCommon.GetIndexByName(pictureBox.Text, this.m_cells);
			this.m_BmpListForm.SetSelectIndex(indexByName);
			this.m_BmpListForm.Show();
			if (1 != this.dataGridView1.SelectedRows.Count)
			{
				foreach (object obj in this.dataGridView1.SelectedRows)
				{
					DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
					this.dataGridView1.Rows[dataGridViewRow.Index].Selected = false;
				}
				this.dataGridView1.Rows[this.m_rowIndex].Selected = true;
			}
		}

		private void picElement5_Click(object sender, EventArgs e)
		{
			this.m_indexPicBox = 4;
			PictureBox pictureBox = sender as PictureBox;
            System.Drawing.Point p = new System.Drawing.Point(pictureBox.Right, pictureBox.Bottom);
			p = this.groupBox2.PointToScreen(p);
            this.m_BmpListForm.Location = new System.Drawing.Point(p.X, p.Y);
			int indexByName = DistributionBoxCommon.GetIndexByName(pictureBox.Text, this.m_cells);
			this.m_BmpListForm.SetSelectIndex(indexByName);
			this.m_BmpListForm.Show();
			if (1 != this.dataGridView1.SelectedRows.Count)
			{
				foreach (object obj in this.dataGridView1.SelectedRows)
				{
					DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
					this.dataGridView1.Rows[dataGridViewRow.Index].Selected = false;
				}
				this.dataGridView1.Rows[this.m_rowIndex].Selected = true;
			}
		}

		private void AddRowInGrid(LoopInfo loopInfo)
		{
			DataGridViewRow dataGridViewRow = new DataGridViewRow();
			DataGridViewTextBoxCell dataGridViewTextBoxCell = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell.Value = loopInfo.loopName;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell);
			DataGridViewTextBoxCell dataGridViewTextBoxCell2 = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell2.Value = loopInfo.phaseSequence;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell2);
			DataGridViewTextBoxCell dataGridViewTextBoxCell3 = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell3.Value = loopInfo.load;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell3);
			DataGridViewTextBoxCell dataGridViewTextBoxCell4 = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell4.Value = loopInfo.coefficient;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell4);
			DataGridViewTextBoxCell dataGridViewTextBoxCell5 = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell5.Value = loopInfo.power;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell5);
			DataGridViewTextBoxCell dataGridViewTextBoxCell6 = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell6.Value = loopInfo.use;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell6);
			DataGridViewTextBoxCell dataGridViewTextBoxCell7 = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell7.Value = loopInfo.current;
			dataGridViewRow.Cells.Add(dataGridViewTextBoxCell7);
			this.dataGridView1.Rows.Add(dataGridViewRow);
		}

		public void SetPicBox(int index)
		{
			if (this.m_indexPicBox == 0)
			{
				this.picElement1.Image = this.m_cells[index].image;
				this.picElement1.Text = this.m_cells[index].name;
				if (index == this.m_cells.Count - 1)
				{
					this.txtTag1.Enabled = false;
				}
				else
				{
					this.txtTag1.Enabled = true;
				}
			}
			if (1 == this.m_indexPicBox)
			{
				this.picElement2.Image = this.m_cells[index].image;
				this.picElement2.Text = this.m_cells[index].name;
				if (index == this.m_cells.Count - 1)
				{
					this.txtTag2.Enabled = false;
				}
				else
				{
					this.txtTag2.Enabled = true;
				}
			}
			if (2 == this.m_indexPicBox)
			{
				this.picElement3.Image = this.m_cells[index].image;
				this.picElement3.Text = this.m_cells[index].name;
				if (index == this.m_cells.Count - 1)
				{
					this.txtTag3.Enabled = false;
				}
				else
				{
					this.txtTag3.Enabled = true;
				}
				this.m_loopInfo[this.m_rowIndex].cells[0] = this.m_cells[index].name;
			}
			if (3 == this.m_indexPicBox)
			{
				this.picElement4.Image = this.m_cells[index].image;
				this.picElement4.Text = this.m_cells[index].name;
				if (index == this.m_cells.Count - 1)
				{
					this.txtTag4.Enabled = false;
				}
				else
				{
					this.txtTag4.Enabled = true;
				}
				this.m_loopInfo[this.m_rowIndex].cells[1] = this.m_cells[index].name;
			}
			if (4 == this.m_indexPicBox)
			{
				this.picElement5.Image = this.m_cells[index].image;
				this.picElement5.Text = this.m_cells[index].name;
				if (index == this.m_cells.Count - 1)
				{
					this.txtTag5.Enabled = false;
				}
				else
				{
					this.txtTag5.Enabled = true;
				}
				this.m_loopInfo[this.m_rowIndex].cells[2] = this.m_cells[index].name;
			}
		}

		public void SetButtonEnabled()
		{
			switch (this.m_indexPicBox)
			{
			case 0:
				if (this.picElement1.Text == "空")
				{
					this.btnTag1.Enabled = false;
					return;
				}
				this.btnTag1.Enabled = true;
				return;
			case 1:
				if (this.picElement2.Text == "空")
				{
					this.btnTag2.Enabled = false;
					return;
				}
				this.btnTag2.Enabled = true;
				return;
			case 2:
				if (this.picElement3.Text == "空")
				{
					this.btnTag3.Enabled = false;
					return;
				}
				this.btnTag3.Enabled = true;
				return;
			case 3:
				if (this.picElement4.Text == "空")
				{
					this.btnTag4.Enabled = false;
					return;
				}
				this.btnTag4.Enabled = true;
				return;
			case 4:
				if (this.picElement5.Text == "空")
				{
					this.btnTag5.Enabled = false;
					return;
				}
				this.btnTag5.Enabled = true;
				return;
			default:
				return;
			}
		}

		private void tbTag3_Leave(object sender, EventArgs e)
		{
			foreach (object obj in this.dataGridView1.SelectedRows)
			{
				DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
				this.m_loopInfo[dataGridViewRow.Index].tags[0] = this.txtTag3.Text;
			}
		}

		private void tbTag4_Leave(object sender, EventArgs e)
		{
			this.m_loopInfo[this.m_rowIndex].tags[1] = this.txtTag4.Text;
		}

		private void tbTag5_Leave(object sender, EventArgs e)
		{
			this.m_loopInfo[this.m_rowIndex].tags[2] = this.txtTag5.Text;
		}

		private void btnDraw_Click(object sender, EventArgs e)
		{
			if (this.dataGridView1.Rows.Count <= 0)
			{
				YJKMessageBox.Show("无回路信息，不能绘制");
				return;
			}
			this.CheckPhase();
			this.SaveSystemDiagramData();
			this.SaveFileData();
		}

		private void CheckPhase()
		{
			bool flag = false;
			foreach (object obj in ((IEnumerable)this.dataGridView1.Rows))
			{
				string b = ((DataGridViewRow)obj).Cells[1].Value.ToString();
				if ("单相" == b)
				{
					flag = true;
					break;
				}
			}
            if (flag && TaskDialog.Show("盈建科", "是否由系统自动平衡并指定各相相序？", (TaskDialogCommonButtons)5) == TaskDialogResult.Ok)
			{
				this.BalancePhase();
			}
		}

		private void SaveSystemDiagramData()
		{
			this.m_busInfo.busModel = this.cmbBusModel.Text;
			this.m_busInfo.busWiring = this.cmbBusWiring.Text;
			this.m_busInfo.busCells[0] = this.picElement1.Text;
			this.m_busInfo.busCells[1] = this.picElement2.Text;
			this.m_busInfo.busTags[0] = this.txtTag1.Text;
			this.m_busInfo.busTags[1] = this.txtTag2.Text;
			this.m_loopCommonInfo.loopModel = this.cmbLoopModel.Text;
			this.m_loopCommonInfo.loopWiring = this.cmbLoopWiring.Text;
			foreach (object obj in ((IEnumerable)this.dataGridView1.Rows))
			{
				int index = ((DataGridViewRow)obj).Index;
				string loopName = this.dataGridView1.Rows[index].Cells[0].Value.ToString();
				string phaseSequence = this.dataGridView1.Rows[index].Cells[1].Value.ToString();
				double load = Convert.ToDouble(this.dataGridView1.Rows[index].Cells[2].Value);
				double coefficient = Convert.ToDouble(this.dataGridView1.Rows[index].Cells[3].Value);
				double power = Convert.ToDouble(this.dataGridView1.Rows[index].Cells[4].Value);
				string use = this.dataGridView1.Rows[index].Cells[5].Value.ToString();
				double current = Convert.ToDouble(this.dataGridView1.Rows[index].Cells[6].Value);
				double pc = DistributionBoxCommon.CalculatePc(load, coefficient);
				double qc = DistributionBoxCommon.CalculateQc(pc, power);
				LoopInfo value = new LoopInfo(loopName, phaseSequence, load, coefficient, power, use, current, this.m_loopInfo[index].cells, this.m_loopInfo[index].tags, pc, qc);
				this.m_loopInfo[index] = value;
			}
			this.m_busCalculateInfo = DistributionBoxCommon.CalculateBusWireData(this.m_busInfo, this.m_loopInfo);
			this.m_busCalculateInfo.Insert(0, this.txtBoxNum.Text);
			this.m_busCalculateInfo.Insert(1, "----");
			this.m_busCalculateInfo.Add(this.txtBoxSize.Text);
			this.m_busCalculateInfo.Add(this.cmbInstallType.Text);
		}

		private void SaveFileData()
		{
			this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "SwitchBox"));
			this.xmlHelper.SetAttribute("Name", this.txtBoxNum.Text);
			this.xmlHelper.SetAttribute("Size", this.txtBoxSize.Text);
			this.xmlHelper.SetAttribute("Install", this.cmbInstallType.Text);
			this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "BusWire"));
			this.xmlHelper.SetAttribute("Name", "进线");
			this.xmlHelper.SetAttribute("Model", this.cmbBusModel.Text);
			this.xmlHelper.SetAttribute("Wiring", this.cmbBusWiring.Text);
			this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "BusWire", "Cell1"));
			this.xmlHelper.SetAttribute("Name", this.picElement1.Text);
			this.xmlHelper.SetAttribute("Tag", this.txtTag1.Text);
			this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "BusWire", "Cell2"));
			this.xmlHelper.SetAttribute("Name", this.picElement2.Text);
			this.xmlHelper.SetAttribute("Tag", this.txtTag2.Text);
			this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "Loops"));
			if (this.xmlHelper.XmlCurNode != null)
			{
				this.xmlHelper.XmlCurNode.RemoveAll();
			}
			this.xmlHelper.SetAttribute("Name", "回路");
			this.xmlHelper.SetAttribute("Model", this.cmbLoopModel.Text);
			this.xmlHelper.SetAttribute("Wiring", this.cmbLoopWiring.Text);
			foreach (LoopInfo loopInfo in this.m_loopInfo)
			{
				XmlElement xmlElement = this.xmlHelper.AddElement("Loop");
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(xmlElement, "Name", loopInfo.loopName);
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(xmlElement, "PhaseSequence", loopInfo.phaseSequence);
				string text = "Load";
				double num = loopInfo.load;
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(xmlElement, text, num.ToString());
				string text2 = "Coefficient";
				num = loopInfo.coefficient;
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(xmlElement, text2, num.ToString());
				string text3 = "Power";
				num = loopInfo.power;
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(xmlElement, text3, num.ToString());
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(xmlElement, "Use", loopInfo.use);
				string text4 = "Current";
				num = loopInfo.current;
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(xmlElement, text4, num.ToString());
				XmlElement node = YArchitech.MEP.Electric.Common.XmlHelper.AddElement(xmlElement, "Cell1");
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(node, "Name", loopInfo.cells[0]);
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(node, "Tag", loopInfo.tags[0]);
				XmlElement node2 = YArchitech.MEP.Electric.Common.XmlHelper.AddElement(xmlElement, "Cell2");
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(node2, "Name", loopInfo.cells[1]);
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(node2, "Tag", loopInfo.tags[1]);
				XmlElement node3 = YArchitech.MEP.Electric.Common.XmlHelper.AddElement(xmlElement, "Cell3");
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(node3, "Name", loopInfo.cells[2]);
				YArchitech.MEP.Electric.Common.XmlHelper.SetAttribute(node3, "Tag", loopInfo.tags[2]);
			}
			this.xmlHelper.SaveXml("");
		}

		private bool ReadFileData()
		{
			try
			{
				if (!File.Exists(this.path))
				{
					return false;
				}
				this.xmlHelper.LoadXml(this.path, "SystemDiagram");
				this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "SwitchBox"));
				this.txtBoxNum.Text = this.xmlHelper.GetAttribute("Name");
				this.txtBoxSize.Text = this.xmlHelper.GetAttribute("Size");
				this.cmbInstallType.Text = this.xmlHelper.GetAttribute("Install");
				this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "BusWire"));
				string attribute = this.xmlHelper.GetAttribute("Model");
				string attribute2 = this.xmlHelper.GetAttribute("Wiring");
				List<string> list = new List<string>();
				List<string> list2 = new List<string>();
				this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "BusWire", "Cell1"));
				string attribute3 = this.xmlHelper.GetAttribute("Name");
				string attribute4 = this.xmlHelper.GetAttribute("Tag");
				list.Add(attribute3);
				list2.Add(attribute4);
				this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "BusWire", "Cell2"));
				attribute3 = this.xmlHelper.GetAttribute("Name");
				attribute4 = this.xmlHelper.GetAttribute("Tag");
				list.Add(attribute3);
				list2.Add(attribute4);
				this.m_busInfo = new BusInfo(attribute, attribute2, list, list2);
				this.xmlHelper.SelectNode(Path.Combine("SystemDiagram", "Loops"));
				string attribute5 = this.xmlHelper.GetAttribute("Model");
				string attribute6 = this.xmlHelper.GetAttribute("Wiring");
				this.m_loopCommonInfo = new LoopCommonInfo(attribute5, attribute6);
				this.m_loopInfo = new List<LoopInfo>();
				foreach (XmlElement xmlElement in this.xmlHelper.GetElements())
				{
					string attribute7 = YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(xmlElement, "Name");
					string attribute8 = YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(xmlElement, "PhaseSequence");
					double load = double.Parse(YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(xmlElement, "Load"));
					double coefficient = double.Parse(YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(xmlElement, "Coefficient"));
					double power = double.Parse(YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(xmlElement, "Power"));
					string attribute9 = YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(xmlElement, "Use");
					double current = double.Parse(YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(xmlElement, "Current"));
					List<string> list3 = new List<string>();
					List<string> list4 = new List<string>();
					foreach (XmlElement node in YArchitech.MEP.Electric.Common.XmlHelper.GetElements(xmlElement))
					{
						attribute3 = YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(node, "Name");
						attribute4 = YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(node, "Tag");
						list3.Add(attribute3);
						list4.Add(attribute4);
					}
					LoopInfo item = new LoopInfo(attribute7, attribute8, load, coefficient, power, attribute9, current, list3, list4, 0.0, 0.0);
					this.m_loopInfo.Add(item);
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			if (e.RowIndex < 0 || e.RowIndex >= this.dataGridView1.Rows.Count)
			{
				return;
			}
			this.m_rowIndex = e.RowIndex;
			this.m_columnIndex = e.ColumnIndex;
			this.m_cmbSelectValue.Items.Clear();
			if (1 == e.ColumnIndex)
			{
				this.m_cmbSelectValue.DropDownStyle = ComboBoxStyle.DropDownList;
				this.m_cmbSelectValue.Items.Add("三相");
				this.m_cmbSelectValue.Items.Add("单相");
				this.m_cmbSelectValue.Items.Add("L1");
				this.m_cmbSelectValue.Items.Add("L2");
				this.m_cmbSelectValue.Items.Add("L3");
				if (this.dataGridView1.CurrentCell.Value != null)
				{
					this.m_cmbSelectValue.Text = this.dataGridView1.CurrentCell.Value.ToString();
				}
                System.Drawing.Rectangle cellDisplayRectangle = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
				this.m_cmbSelectValue.Left = cellDisplayRectangle.Left;
				this.m_cmbSelectValue.Top = cellDisplayRectangle.Top;
				this.m_cmbSelectValue.Width = cellDisplayRectangle.Width;
				this.m_cmbSelectValue.Height = cellDisplayRectangle.Height;
				this.m_cmbSelectValue.Visible = true;
			}
			else if (5 == e.ColumnIndex)
			{
				this.m_cmbSelectValue.DropDownStyle = ComboBoxStyle.DropDown;
				this.m_cmbSelectValue.Items.Add("照明");
				this.m_cmbSelectValue.Items.Add("插座");
				this.m_cmbSelectValue.Items.Add("备用");
				if (this.dataGridView1.CurrentCell.Value != null)
				{
					this.m_cmbSelectValue.Text = this.dataGridView1.CurrentCell.Value.ToString();
				}
                System.Drawing.Rectangle cellDisplayRectangle2 = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
				this.m_cmbSelectValue.Left = cellDisplayRectangle2.Left;
				this.m_cmbSelectValue.Top = cellDisplayRectangle2.Top;
				this.m_cmbSelectValue.Width = cellDisplayRectangle2.Width;
				this.m_cmbSelectValue.Height = cellDisplayRectangle2.Height;
				this.m_cmbSelectValue.Visible = true;
			}
			else
			{
				this.m_cmbSelectValue.Visible = false;
				this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
				this.dataGridView1.BeginEdit(true);
			}
			LoopInfo loopInfo = this.m_loopInfo[e.RowIndex];
			this.groupBox2.Text = loopInfo.loopName;
			this.picElement3.Image = DistributionBoxCommon.GetCellImageByName(loopInfo.cells[0], this.m_cells);
			this.picElement3.Text = loopInfo.cells[0];
			this.picElement4.Image = DistributionBoxCommon.GetCellImageByName(loopInfo.cells[1], this.m_cells);
			this.picElement4.Text = loopInfo.cells[1];
			this.picElement5.Image = DistributionBoxCommon.GetCellImageByName(loopInfo.cells[2], this.m_cells);
			this.picElement5.Text = loopInfo.cells[2];
			this.txtTag3.Text = loopInfo.tags[0];
			this.txtTag4.Text = loopInfo.tags[1];
			this.txtTag5.Text = loopInfo.tags[2];
			if (this.picElement3.Text == "空")
			{
				this.txtTag3.Enabled = false;
			}
			else
			{
				this.txtTag3.Enabled = true;
			}
			if (this.picElement4.Text == "空")
			{
				this.txtTag4.Enabled = false;
			}
			else
			{
				this.txtTag4.Enabled = true;
			}
			if (this.picElement5.Text == "空")
			{
				this.txtTag5.Enabled = false;
				return;
			}
			this.txtTag5.Enabled = true;
		}

		private void btnAddLoop_Click(object sender, EventArgs e)
		{
			AddLoopForm addLoopForm = new AddLoopForm("添加回路");
			DialogResult dialogResult = addLoopForm.ShowDialog();
			if (DialogResult.OK == dialogResult)
			{
				int num = int.Parse(addLoopForm.NumLoop);
				for (int i = 0; i < num; i++)
				{
					string loopName = string.Format("WL{0}", this.m_loopInfo.Count + 1);
					string phaseSequence = addLoopForm.PhaseSequence;
					double load = double.Parse(addLoopForm.Load);
					double coefficient = double.Parse(addLoopForm.Coefficient);
					double power = double.Parse(addLoopForm.Power);
					string use = addLoopForm.Use;
					double current = 4.55;
					List<string> list = new List<string>();
					List<string> list2 = new List<string>();
					list.Add("断路器");
					list2.Add("");
					list.Add("空");
					list2.Add("");
					list.Add("空");
					list2.Add("");
					LoopInfo loopInfo = new LoopInfo(loopName, phaseSequence, load, coefficient, power, use, current, list, list2, 0.0, 0.0);
					this.m_loopInfo.Add(loopInfo);
					this.AddRowInGrid(loopInfo);
				}
			}
		}

		private void btnEditLoop_Click(object sender, EventArgs e)
		{
			if (this.dataGridView1.SelectedRows.Count <= 0)
			{
				return;
			}
			AddLoopForm addLoopForm = new AddLoopForm("编辑回路");
			DialogResult dialogResult = addLoopForm.ShowDialog();
			if (DialogResult.OK == dialogResult)
			{
				foreach (object obj in this.dataGridView1.SelectedRows)
				{
					int index = ((DataGridViewRow)obj).Index;
					this.dataGridView1.Rows[index].Cells[1].Value = addLoopForm.PhaseSequence;
					this.dataGridView1.Rows[index].Cells[2].Value = addLoopForm.Load;
					this.dataGridView1.Rows[index].Cells[3].Value = addLoopForm.Coefficient;
					this.dataGridView1.Rows[index].Cells[4].Value = addLoopForm.Power;
					this.dataGridView1.Rows[index].Cells[5].Value = addLoopForm.Use;
					this.SetElectricCurrent(index);
				}
			}
		}

		private void btnDeleteLoop_Click(object sender, EventArgs e)
		{
			this.m_cmbSelectValue.Visible = false;
			if (this.dataGridView1.SelectedRows.Count <= 0)
			{
				return;
			}
			if (this.dataGridView1.SelectedRows.Count == this.dataGridView1.Rows.Count)
			{
				TaskDialog.Show("盈建科", "请至少保留一个回路。");
				return;
			}
			int num = this.dataGridView1.SelectedRows[0].Index;
			foreach (object obj in this.dataGridView1.SelectedRows)
			{
				num = ((DataGridViewRow)obj).Index;
				this.m_loopInfo.RemoveAt(num);
				this.dataGridView1.Rows.RemoveAt(num);
			}
			if (num >= this.m_loopInfo.Count)
			{
				num = this.m_loopInfo.Count - 1;
			}
			LoopInfo loopInfo = this.m_loopInfo[num];
			this.groupBox2.Text = loopInfo.loopName;
			this.picElement3.Image = DistributionBoxCommon.GetCellImageByName(loopInfo.cells[0], this.m_cells);
			this.picElement3.Text = loopInfo.cells[0];
			this.picElement4.Image = DistributionBoxCommon.GetCellImageByName(loopInfo.cells[1], this.m_cells);
			this.picElement4.Text = loopInfo.cells[1];
			this.picElement5.Image = DistributionBoxCommon.GetCellImageByName(loopInfo.cells[2], this.m_cells);
			this.picElement5.Text = loopInfo.cells[2];
			this.txtTag3.Text = loopInfo.tags[0];
			this.txtTag4.Text = loopInfo.tags[1];
			this.txtTag5.Text = loopInfo.tags[2];
			if (this.picElement3.Text == "空")
			{
				this.txtTag3.Enabled = false;
			}
			else
			{
				this.txtTag3.Enabled = true;
			}
			if (this.picElement4.Text == "空")
			{
				this.txtTag4.Enabled = false;
			}
			else
			{
				this.txtTag4.Enabled = true;
			}
			if (this.picElement5.Text == "空")
			{
				this.txtTag5.Enabled = false;
				return;
			}
			this.txtTag5.Enabled = true;
		}

		private void btnRestoreData_Click(object sender, EventArgs e)
		{
			if (!this.ReadFileData())
			{
				this.InitSystemDiagramData();
			}
			this.InitDlgData();
			this.SetButtonEnabled();
		}

		private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			if (e.ColumnIndex == 0)
			{
				try
				{
					string text = this.dataGridView1.CurrentCell.Value.ToString();
					if (text == null)
					{
						throw new Exception();
					}
					LoopInfo value = this.m_loopInfo[e.RowIndex];
					value.loopName = text;
					this.m_loopInfo[e.RowIndex] = value;
				}
				catch
				{
					TaskDialog.Show("盈建科", "回路名称不能为空！");
					this.dataGridView1.CurrentCell.Value = this.m_loopInfo[e.RowIndex].loopName;
				}
				return;
			}
			if (2 == e.ColumnIndex)
			{
				try
				{
					if (Convert.ToDouble(this.dataGridView1.CurrentCell.Value) < 0.0)
					{
						throw new Exception();
					}
					goto IL_204;
				}
				catch
				{
					TaskDialog.Show("盈建科", "负载值应为正数！");
					this.dataGridView1.CurrentCell.Value = this.m_loopInfo[e.RowIndex].load;
					goto IL_204;
				}
			}
			if (3 == e.ColumnIndex)
			{
				try
				{
					double num = Convert.ToDouble(this.dataGridView1.CurrentCell.Value);
					if (num <= 0.0 || num > 1.0)
					{
						throw new Exception();
					}
					goto IL_204;
				}
				catch
				{
					TaskDialog.Show("盈建科", "需用系数值在0~1之间！");
					this.dataGridView1.CurrentCell.Value = this.m_loopInfo[e.RowIndex].coefficient;
					goto IL_204;
				}
			}
			if (4 == e.ColumnIndex)
			{
				try
				{
					double num2 = Convert.ToDouble(this.dataGridView1.CurrentCell.Value);
					if (num2 <= 0.0 || num2 > 1.0)
					{
						throw new Exception();
					}
				}
				catch
				{
					TaskDialog.Show("盈建科", "功率因数值在0~1之间！");
					this.dataGridView1.CurrentCell.Value = this.m_loopInfo[e.RowIndex].power;
				}
			}
			IL_204:
			this.SetElectricCurrent(e.RowIndex);
		}

		private void SetElectricCurrent(int index)
		{
            //double activePower = DataCalculationAndHelper.ActivePower(Convert.ToDouble(this.dataGridView1.Rows[index].Cells[2].Value), Convert.ToDouble(this.dataGridView1.Rows[index].Cells[3].Value));
            //double reactivePower = DataCalculationAndHelper.RectivePower(activePower, Convert.ToDouble(this.dataGridView1.Rows[index].Cells[4].Value));
            //double viewPower = DataCalculationAndHelper.ViewPower(activePower, reactivePower);
            //double var;
            //if (this.dataGridView1.Rows[index].Cells[1].Value.ToString() == "三相")
            //{
            //    var = DataCalculationAndHelper.EleCurrentThree(viewPower);
            //}
            //else
            //{
            //    var = DataCalculationAndHelper.EleCurrentOne(viewPower);
            //}
            //this.dataGridView1.Rows[index].Cells[6].Value = DataCalculationAndHelper.MathDecimal(var, 2);
		}

		private void btnBalancePhase_Click(object sender, EventArgs e)
		{
			this.BalancePhase();
		}

		private void BalancePhase()
		{
			List<Phase> list = new List<Phase>();
			for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
			{
				if (this.dataGridView1.Rows[i].Cells[1].Value.ToString() != "三相")
				{
					Phase item = new Phase(i, Convert.ToDouble(this.dataGridView1.Rows[i].Cells[2].Value));
					list.Add(item);
				}
			}
			if (list.Count < 1)
			{
				return;
			}
			list.Sort(new LoadComparer());
			List<Phase> list2 = new List<Phase>();
			List<Phase> list3 = new List<Phase>();
			List<Phase> list4 = new List<Phase>();
			int count = list.Count;
			if (count < 2)
			{
				list2.Add(list[0]);
			}
			else
			{
				list2.Add(list[0]);
				list3.Add(list[1]);
				double num = DistributionBoxCommon.Average(list, 3);
				double num2 = list2[0].value;
				for (int j = 2; j < count; j++)
				{
					if (num2 + list[j].value <= num)
					{
						num2 += list[j].value;
						list2.Add(list[j]);
					}
				}
				foreach (Phase item2 in list2)
				{
					list.Remove(item2);
				}
				num = DistributionBoxCommon.Average(list, 2);
				num2 = list3[0].value;
				if (list.Count > 2)
				{
					for (int k = 1; k < list.Count; k++)
					{
						if (num2 + list[k].value <= num)
						{
							num2 += list[k].value;
							list3.Add(list[k]);
						}
					}
				}
				foreach (Phase item3 in list3)
				{
					list.Remove(item3);
				}
				list4.AddRange(list);
			}
			foreach (Phase phase in list2)
			{
				this.dataGridView1.Rows[phase.index].Cells[1].Value = "L1";
				DataGridViewCell dataGridViewCell = this.dataGridView1.Rows[phase.index].Cells[2];
				double value = phase.value;
				dataGridViewCell.Value = value.ToString();
			}
			foreach (Phase phase2 in list3)
			{
				this.dataGridView1.Rows[phase2.index].Cells[1].Value = "L2";
				DataGridViewCell dataGridViewCell2 = this.dataGridView1.Rows[phase2.index].Cells[2];
				double value = phase2.value;
				dataGridViewCell2.Value = value.ToString();
			}
			foreach (Phase phase3 in list4)
			{
				this.dataGridView1.Rows[phase3.index].Cells[1].Value = "L3";
				DataGridViewCell dataGridViewCell3 = this.dataGridView1.Rows[phase3.index].Cells[2];
				double value = phase3.value;
				dataGridViewCell3.Value = value.ToString();
			}
		}

		private void SystemCreateForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private void btnSelBox_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Yes;
		}

		public void ResetLoopInfo(string strBoxNum, List<LoopInfo> lstNewLoopInfo)
		{
			this.txtBoxNum.Text = strBoxNum;
			if (this.m_loopInfo == null)
			{
				this.m_loopInfo = new List<LoopInfo>();
			}
			else
			{
				this.m_loopInfo.Clear();
			}
			for (int i = 0; i < lstNewLoopInfo.Count; i++)
			{
				LoopInfo item = new LoopInfo(lstNewLoopInfo[i]);
				this.m_loopInfo.Add(item);
			}
			this.InitDlgData();
			this.SetButtonEnabled();
		}

		private void GetAllTags()
		{
			if (this.m_dictionary == null)
			{
				return;
			}
			this.m_xmlTagData.SelectNode("SwitchTags");
			foreach (XmlElement xmlElement in this.m_xmlTagData.GetElements())
			{
				string attribute = xmlElement.GetAttribute("Name");
				List<string> list = new List<string>();
				XmlNodeList childNodes = xmlElement.ChildNodes;
				for (int i = 0; i < childNodes.Count; i++)
				{
					XmlElement xmlElement2 = childNodes[i] as XmlElement;
					list.Add(xmlElement2.GetAttribute("Name"));
				}
				this.m_dictionary.Add(attribute, list);
			}
		}

		public void SaveTage(List<string> lstTag)
		{
			this.m_xmlTagData.SelectNode("SwitchTags");
			foreach (XmlElement xmlElement in this.m_xmlTagData.GetElements())
			{
				if (xmlElement.GetAttribute("Name") == this.m_strKey)
				{
					xmlElement.RemoveAll();
					xmlElement.SetAttribute("Name", this.m_strKey);
					foreach (string value in lstTag)
					{
						YArchitech.MEP.Electric.Common.XmlHelper.AddElement(xmlElement, "Tag").SetAttribute("Name", value);
					}
					this.m_dictionary.Remove(this.m_strKey);
					this.m_dictionary.Add(this.m_strKey, lstTag);
					this.m_xmlTagData.SaveXml("");
					break;
				}
			}
		}

		private void btnTag1_Click(object sender, EventArgs e)
		{
			this.m_indexPicBox = 0;
			this.m_strKey = this.picElement1.Text;
			List<string> lstTag = this.m_dictionary[this.m_strKey];
			new SwitchTagForm(this, lstTag).ShowDialog();
		}

		private void btnTag2_Click(object sender, EventArgs e)
		{
			this.m_indexPicBox = 1;
			this.m_strKey = this.picElement2.Text;
			List<string> lstTag = this.m_dictionary[this.m_strKey];
			new SwitchTagForm(this, lstTag).ShowDialog();
		}

		private void btnTag3_Click(object sender, EventArgs e)
		{
			this.m_indexPicBox = 2;
			this.m_strKey = this.picElement3.Text;
			List<string> lstTag = this.m_dictionary[this.m_strKey];
			new SwitchTagForm(this, lstTag).Show();
		}

		private void btnTag4_Click(object sender, EventArgs e)
		{
			this.m_indexPicBox = 3;
			this.m_strKey = this.picElement4.Text;
			List<string> lstTag = this.m_dictionary[this.m_strKey];
			new SwitchTagForm(this, lstTag).Show();
		}

		private void btnTag5_Click(object sender, EventArgs e)
		{
			this.m_indexPicBox = 4;
			this.m_strKey = this.picElement5.Text;
			List<string> lstTag = this.m_dictionary[this.m_strKey];
			new SwitchTagForm(this, lstTag).Show();
		}

		public void SetTagText(string strText)
		{
			switch (this.m_indexPicBox)
			{
			case 0:
				this.txtTag1.Text = strText;
				return;
			case 1:
				this.txtTag2.Text = strText;
				return;
			case 2:
				this.txtTag3.Text = strText;
				IEnumerator enumerator = this.dataGridView1.SelectedRows.GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						object obj = enumerator.Current;
						DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
						this.m_loopInfo[dataGridViewRow.Index].tags[0] = this.txtTag3.Text;
					}
					return;
				}
				break;
			case 3:
				break;
			case 4:
				goto IL_11E;
			default:
				return;
			}
			this.txtTag4.Text = strText;
            //IEnumerator enumerator = this.dataGridView1.SelectedRows.GetEnumerator();
            //{
            //    while (enumerator.MoveNext())
            //    {
            //        object obj2 = enumerator.Current;
            //        DataGridViewRow dataGridViewRow2 = (DataGridViewRow)obj2;
            //        this.m_loopInfo[dataGridViewRow2.Index].tags[0] = this.txtTag4.Text;
            //    }
            //    return;
            //}
			IL_11E:
			this.txtTag5.Text = strText;
			foreach (object obj3 in this.dataGridView1.SelectedRows)
			{
				DataGridViewRow dataGridViewRow3 = (DataGridViewRow)obj3;
				this.m_loopInfo[dataGridViewRow3.Index].tags[0] = this.txtTag5.Text;
			}
		}

		public List<CellInfo> m_cells;

		private BmpListForm m_BmpListForm;

		private int m_rowIndex;

		private int m_columnIndex;

		private int m_indexPicBox;

		private BusInfo m_busInfo;

		private LoopCommonInfo m_loopCommonInfo;

		private List<LoopInfo> m_loopInfo = new List<LoopInfo>();

		private List<string> m_busCalculateInfo = new List<string>();

        private System.Windows.Forms.ComboBox m_cmbSelectValue = new System.Windows.Forms.ComboBox();

		private YArchitech.MEP.Electric.Common.XmlHelper xmlHelper = new YArchitech.MEP.Electric.Common.XmlHelper();

		private string path = Path.Combine(Product.WorkingLocation, "SystemCreate.xml");

		private const string SystemDiagram = "SystemDiagram";

		private const string SwitchBox = "SwitchBox";

		private const string BusWire = "BusWire";

		private const string Model = "Model";

		private const string Wiring = "Wiring";

		private const string Cell1 = "Cell1";

		private const string Cell2 = "Cell2";

		private const string Cell3 = "Cell3";

		private const string CellName = "Name";

		private const string CellTag = "Tag";

		private const string Loops = "Loops";

		private const string Loop = "Loop";

		private const string LoopName = "Name";

		private const string PhaseSequence = "PhaseSequence";

		private new const string Load = "Load";

		private const string Coefficient = "Coefficient";

		private const string Power = "Power";

		private const string Use = "Use";

		private const string Current = "Current";

		private const string BoxName = "Name";

		private const string BoxSize = "Size";

		private const string BoxInstall = "Install";

		private Dictionary<string, List<string>> m_dictionary;

		private string m_strKey = "";

		private YArchitech.MEP.Electric.Common.XmlHelper m_xmlTagData;

		private const string root = "SwitchTags";

		private const string switchTag = "SwitchTag";

		private const string tag = "Tag";

		private const string name = "Name";

		private DataGridViewTextBoxColumn dgvColumnLoopName;

		private DataGridViewTextBoxColumn dgvColumnPhaseSequence;

		private DataGridViewTextBoxColumn dgvColumnLoad;

		private DataGridViewTextBoxColumn dgvColumnCoefficient;

		private DataGridViewTextBoxColumn dgvColumnPower;

		private DataGridViewTextBoxColumn dgvColumnUse;

		private DataGridViewTextBoxColumn dgvColumnCurrent;
	}
}
